package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.api.SysCompanyControllerApi;
import com.nineclock.system.dto.SysChangeMainManagerDTO;
import com.nineclock.system.service.SysCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/company")
public class SysCompanyController implements SysCompanyControllerApi {
    @Autowired
    private SysCompanyService sysCompanyService;

    /**
     * 查询当前企业信息
     *
     * @return
     */
    @GetMapping
    @Override
    public Result queryCompanyInfo() {
        return Result.success(sysCompanyService.queryCompanyInfo());
    }

    /**
     * 上传图片
     *
     * @return
     */
    @PostMapping("/uploadOSS")
    @Override
    public Result uploadOSS(MultipartFile file) {
        return Result.success(sysCompanyService.uploadOSS(file));
    }

    /**
     * 修改企业信息
     *
     * @param map
     * @return
     */
    @PutMapping
    @Override
    public Result modifyCompanyInfo(@RequestBody Map<String, String> map) {
        sysCompanyService.modifyCompanyInfo(map);
        return Result.success();
    }

    /**
     * 获取企业当前主管理员
     *
     * @return
     */

    @GetMapping("/getCurrentAdmin")
    public Result getCurrentAdmin() {
        return Result.success(sysCompanyService.getCurrentAdmin());
    }

    /**
     * 更改系统管理员
     *
     * @param
     * @return
     */
    @PostMapping("/config/admin")
    public Result updateAdmin(@RequestBody SysChangeMainManagerDTO dto) {
        sysCompanyService.updateAdmin(dto);
        return Result.success("更该系统管理员成功!");
    }
}
